<?php

$v_db_host = "localhost";
$v_db_database = "wedding";
$v_db_user = "root";
$v_db_pass = "root";
$arr_table_column = array();
$cnn = mysql_connect($v_db_host, $v_db_user, $v_db_pass) or die("Could not connect : " . mysql_error());
mysql_select_db($v_db_database);

$v_table_name = isset($_REQUEST["txt_table_name"]) ? $_REQUEST["txt_table_name"] : "";
$v_url = isset($_REQUEST["txt_url"]) ? $_REQUEST["txt_url"] : "";
$v_directory = isset($_REQUEST["txt_directory"]) ? $_REQUEST["txt_directory"] : "";
if ($v_table_name != "") {
	$rs_column = mysql_query(" SHOW COLUMNS FROM " . $v_table_name . " ") or die(mysql_error());
	$i = 0;
	while ($arr_column = mysql_fetch_array($rs_column, MYSQL_NUM)) {
		$arr_table_column[$i][0] = $arr_column[0];
		$arr_table_column[$i][1] = $arr_column[1];
		$i++;
	}
	if (mkdir($v_directory)) {
		$filename = $v_directory . "/qry_all_" . str_replace("tb_", "", strtolower($v_table_name)) . ".php";
		if ($handle = fopen($filename, 'w')) {
			fwrite($handle, create_qry_all_file());
			fclose($handle);
		}
		$filename = $v_directory . "/dsp_all_" . str_replace("tb_", "", strtolower($v_table_name)) . ".php";
		if ($handle = fopen($filename, 'w')) {
			fwrite($handle, create_dsp_all_file());
			fclose($handle);
		}
/*
		$filename = $v_directory . "/qry_singer_" . str_replace("tb_", "", strtolower($v_table_name)) . ".php";
		if ($handle = fopen($filename, 'w')) {
			fwrite($handle, create_qry_singer_file());
			fclose($handle);
		}

		$filename = $v_directory . "/dsp_singer_" . str_replace("tb_", "", strtolower($v_table_name)) . ".php";
		if ($handle = fopen($filename, 'w')) {
			fwrite($handle, create_dsp_singer_file());
			fclose($handle);
		}*/
		$filename = $v_directory . "/act_delete_" . str_replace("tb_", "", strtolower($v_table_name)) . ".php";
		if ($handle = fopen($filename, 'w')) {
			fwrite($handle, create_delete_file());
			fclose($handle);
		}
		$filename = $v_directory . "/act_update_" . str_replace("tb_", "", strtolower($v_table_name)) . ".php";
		if ($handle = fopen($filename, 'w')) {
			fwrite($handle, create_update_file());
			fclose($handle);
		}
		$filename = $v_directory . "/ajax_load_" . str_replace("tb_", "", strtolower($v_table_name)) . "_info.php";
		if ($handle = fopen($filename, 'w')) {
			fwrite($handle, create_ajax_info_file());
			fclose($handle);
		}

		$filename = $v_directory . "/index.php";
		if ($handle = fopen($filename, 'w')) {
			fwrite($handle, create_index_file());
			fclose($handle);
		}
	} else {
		echo "failed to create directory";
	}
	//echo "<pre style='background-color:#f2f2f2;'>";
	//echo highlight_string(create_index_file());
	//echo highlight_string(create_qry_singer_file());
	//highlight_string(create_qry_all_file());
	//echo highlight_string(create_delete_file());
	//echo highlight_string(create_update_file());
	//highlight_string(create_dsp_singer_file());
	//highlight_string(create_dsp_all_file());
	//echo "</pre>";	
} else {
	echo
	"
	<form action='' method='get'>
		C&#244;ng d&#7909;ng: T&#7921; &#273;&#7897;ng sinh ra m&#7897;t th&#432; m&#7909;c v&#224; c&#225;c file code th&#7921;c hi&#7879;n c&#225;c ch&#7913;c n&#259;ng c&#259;n b&#7843;n cho m&#7897;t b&#7843;ng d&#7919; li&#7879;u.<BR>
		S&#7917; d&#7909;ng khi t&#7841;o th&#234;m m&#7897;t b&#7843;ng trong CSDL v&#224; mu&#7889;n c&#243; ph&#7847;n qu&#7843;n tr&#7883; c&#259;n b&#7843;n (Th&#234;m, S&#7917;a, X&#243;a, Li&#7879;t k&#234; danh s&#225;ch) tr&#234;n b&#7843;ng n&#224;y<BR>
		T&#234;n c&#225;c file trong th&#432; m&#7909;c &#273;&#432;&#7907;c &#273;&#7863;t theo t&#234;n b&#7843;ng<br>
		To&#224;n b&#7897; c&#225;c h&#224;m s&#7917; l&#253; d&#7919; li&#7879;u &#273;&#432;&#7907;c l&#432;u t&#7841;m th&#7901;i v&#224;o File Index.php trong th&#432; m&#7909;c sinh ra (C&#243; th&#7875; coppy ra file function ngo&#224;i n&#7871;u c&#7847;n)<BR>
		C&#225;c th&#244;ng s&#7889; :<BR>
		TABLE: t&#234;n b&#7843;ng trong CSDL s&#7869; d&#249;ng &#273;&#7875; c&#7853;p nh&#7853;t th&#244;ng tin. (VD: TB_PRODUCT)<BR>
		URL: URL &#273;&#7875; &#273;&#7871;n &#273;&#432;&#7907;c th&#432; m&#7909;c n&#224;y (VD: ?ga=MA)<BR>
		Directory: T&#234;n th&#432; m&#7909;c ch&#7913;a c&#225;c file(VD manger/product)<BR>
		TABLE: <input type='text' name = 'txt_table_name' value=''>
		URL:<input type='text' name = 'txt_url' value=''>
		Directory:<input  type='text' name = 'txt_directory' value=''>
		<input type='submit' value='Create'>
	</form>
	";
}
mysql_close($cnn);

function create_index_file() {
	global $arr_table_column, $v_table_name, $v_url;
	$arr_url = explode("=", $v_url);
	$p_parent_action = $arr_url[sizeof($arr_url) - 1];
	$v_str = "<?php if (!isset(\$v_sval)) exit; ?>
<?php
	\$" . strtolower(substr(str_replace("TB_", "", strtoupper($v_table_name)), 0, 4)) . " = (isset(\$_REQUEST[\"" . strtolower(substr(str_replace("TB_", "", strtoupper($v_table_name)), 0, 4)) . "\"])) ? \$_REQUEST[\"" . strtolower(substr(str_replace("TB_", "", strtoupper($v_table_name)), 0, 4)) . "\"] : \"\" ;
	
	switch(\$" . strtolower(substr(str_replace("TB_", "", strtoupper($v_table_name)), 0, 4)) . "){
		case \"A\";
			include \"qry_all_" . str_replace("tb_", "", strtolower($v_table_name)) . ".php\";
			include \"account/header.php\";
			include \"dsp_all_" . str_replace("tb_", "", strtolower($v_table_name)) . ".php\";
			include \"account/footer.php\";
			break;
		case \"" . substr(str_replace("TB_", "", strtoupper($v_table_name)), 0, 2) . "IF\";
			include \"ajax_load_" . str_replace("tb_", "", strtolower($v_table_name)) . "_info.php\";
			break;
		case \"D\";
			include \"act_delete_" . str_replace("tb_", "", strtolower($v_table_name)) . ".php\";		
			break;
		case \"U\";
			include \"act_update_" . str_replace("tb_", "", strtolower($v_table_name)) . ".php\";		
			break;
		default ;
			include \"qry_all_" . str_replace("tb_", "", strtolower($v_table_name)) . ".php\";
			include \"account/header.php\";
			include \"dsp_all_" . str_replace("tb_", "", strtolower($v_table_name)) . ".php\";
			include \"account/footer.php\";
	}
";

	$v_str.="
	function insert" . ucfirst(str_replace("tb_", "", strtolower($v_table_name))) . "(
";
	for ($i = 1; $i < sizeof($arr_table_column); $i++) {
		if ($i == 1)
			$v_str.="		\$p_" . strtolower($arr_table_column[$i][0]) . "\r\n";
		else
			$v_str.="			,\$p_" . strtolower($arr_table_column[$i][0]) . "\r\n";
	}
	$v_str.="	
	){
		mysql_query(\"
			INSERT INTO " . strtoupper($v_table_name) . "(
";
	for ($i = 1; $i < sizeof($arr_table_column); $i++) {
		if ($i == 1)
			$v_str.="				" . strtoupper($arr_table_column[$i][0]) . "\r\n";
		else
			$v_str.="					," . strtoupper($arr_table_column[$i][0]) . "\r\n";
	}
	$v_str.="	
			)VALUES(
";
	for ($i = 1; $i < sizeof($arr_table_column); $i++) {
		if ($i == 1)
			$v_str.="				'\".\$p_" . strtolower($arr_table_column[$i][0]) . ".\"'" . "\r\n";
		else
			$v_str.="					,'\".\$p_" . strtolower($arr_table_column[$i][0]) . ".\"'" . "\r\n";
	}
	$v_str.="	
			)	
		\")or die(mysql_error());
		return mysql_insert_id();
	}
	
	function update" . ucfirst(str_replace("tb_", "", strtolower($v_table_name))) . "(
";
	for ($i = 0; $i < sizeof($arr_table_column); $i++) {
		if ($i == 0)
			$v_str.="		\$p_" . strtolower($arr_table_column[$i][0]) . "\r\n";
		else
			$v_str.="			,\$p_" . strtolower($arr_table_column[$i][0]) . "\r\n";
	}
	$v_str.="	
	){
		mysql_query(\"
			UPDATE " . strtoupper($v_table_name) . " 
			SET
";
	for ($i = 1; $i < sizeof($arr_table_column); $i++) {
		if ($i == 1)
			$v_str .= "				" . strtoupper($arr_table_column[$i][0]) . "='\".\$p_" . strtolower($arr_table_column[$i][0]) . ".\"'" . "\r\n";
		else
			$v_str.="					," . strtoupper($arr_table_column[$i][0]) . "='\".\$p_" . strtolower($arr_table_column[$i][0]) . ".\"'" . "\r\n";
	}
	$v_str.="	
			WHERE " . strtoupper($arr_table_column[0][0]) . " =  '\"." . "\$p_" . strtolower($arr_table_column[0][0]) . ".\"'
		\");
	}
";



	$v_str.="
	function getAll" . ucfirst(str_replace("tb_", "", strtolower($v_table_name))) . "(\$p_where_clause,\$p_offset,\$p_num_row,\$p_order_by=\" " . strtoupper($arr_table_column[0][0]) . " DESC \"){
		\$rs = mysql_query(\"
		SELECT 
";

	for ($i = 0; $i < sizeof($arr_table_column); $i++) {
		if ($i == 0)
			$v_str.="			" . strtoupper($arr_table_column[$i][0]) . "\r\n";
		else
			$v_str.="				," . strtoupper($arr_table_column[$i][0]) . "\r\n";
	}

	$v_str.="
		FROM " . strtoupper($v_table_name) . "	
		WHERE 1 \".\$p_where_clause.\"		
		ORDER BY \".\$p_order_by.\"
		LIMIT \".\$p_offset.\",\".\$p_num_row.\"
		\")or die(mysql_error());
		return \$rs;
	}
";

	$v_str.="
	function getSinger" . ucfirst(str_replace("tb_", "", strtolower($v_table_name))) . "(" . "\$p_" . strtolower($arr_table_column[0][0]) . "){
		\$rs = mysql_query(\"
		SELECT 
";

	for ($i = 0; $i < sizeof($arr_table_column); $i++) {
		if ($i == 0)
			$v_str.="			" . strtoupper($arr_table_column[$i][0]) . "\r\n";
		else
			$v_str.="				," . strtoupper($arr_table_column[$i][0]) . "\r\n";
	}

	$v_str.="
		FROM " . strtoupper($v_table_name) . "	
		WHERE " . strtoupper($arr_table_column[0][0]) . " =  '\"." . "\$p_" . strtolower($arr_table_column[0][0]) . ".\"'		
		\")or die(mysql_error());
		return \$rs;
	}
";

	$v_str.="
?>	
";
	return $v_str;
}

function create_qry_singer_file() {
	global $arr_table_column, $v_table_name;
	$v_str = "<?php if (!isset(\$v_sval)) exit; ?>
	<?php
	" . "\$v_" . strtolower($arr_table_column[0][0]) . " = (isset(\$_REQUEST[\"hdn_" . strtolower($arr_table_column[0][0]) . "\"])) ? \$_REQUEST[\"hdn_" . strtolower($arr_table_column[0][0]) . "\"] : 0;
";
	$v_str .= "
	\$rs_" . str_replace("tb_", "", strtolower($v_table_name)) . " = getSinger" . str_replace("tb_", "", strtolower($v_table_name)) . "(" . "\$v_" . strtolower($arr_table_column[0][0]) . ");
	if (\$arr_" . str_replace("tb_", "", strtolower($v_table_name)) . " = mysql_fetch_array(\$rs_" . str_replace("tb_", "", strtolower($v_table_name)) . ",MYSQL_NUM)){
";

	for ($i = 0; $i < sizeof($arr_table_column); $i++) {
		if ($i == 0)
			$v_str.="		\$v_" . strtolower($arr_table_column[$i][0]) . "=\$arr_" . str_replace("tb_", "", strtolower($v_table_name)) . "[\"" . $i . "\"];\r\n";
		else
			$v_str.="			\$v_" . strtolower($arr_table_column[$i][0]) . "=\$arr_" . str_replace("tb_", "", strtolower($v_table_name)) . "[\"" . $i . "\"];\r\n";
	}
	$v_str .= "
	}else{
";
	for ($i = 0; $i < sizeof($arr_table_column); $i++) {
		if ($i == 0)
			$v_str.="		\$v_" . strtolower($arr_table_column[$i][0]) . "=\"\";\r\n";
		else
			$v_str.="			\$v_" . strtolower($arr_table_column[$i][0]) . "=\"\";\r\n";
	}
	$v_str .= "
	}
";

	$v_str .= "
?>
";
	return $v_str;
}

function create_qry_all_file() {
	global $arr_table_column, $v_table_name, $v_url;
	$arr_url = explode("=", $v_url);
	$v_parent_action = $arr_url[sizeof($arr_url) - 1];
	$v_str = "<?php if (!isset(\$v_sval)) exit; ?>
<?php
\$v_offset = (isset(\$_REQUEST[\"hdn_offset\"])) ? \$_REQUEST[\"hdn_offset\"] : 0;
\$v_num_row = (isset(\$_REQUEST[\"hdn_num_row\"])) ? \$_REQUEST[\"hdn_num_row\"] : SYS_ITEMS_PER_PAGE;
";
	for ($i = 0; $i < sizeof($arr_table_column); $i++) {
		if ($i == 0)
			$v_str .= "\$v_" . strtolower($arr_table_column[0][0]) . " = (isset(\$_REQUEST[\"txt_" . strtolower($arr_table_column[0][0]) . "\"])) ? \$_REQUEST[\"txt_" . strtolower($arr_table_column[0][0]) . "\"] : 0;\r\n";
		else
			$v_str .= "\$v_" . strtolower($arr_table_column[$i][0]) . " = (isset(\$_REQUEST[\"txt_" . strtolower($arr_table_column[$i][0]) . "\"])) ? \$_REQUEST[\"txt_" . strtolower($arr_table_column[$i][0]) . "\"] : 0;\r\n";
	}

	$v_str.="		
\$v_where_clause = \"\";
\$rs_all_" . str_replace("tb_", "", strtolower($v_table_name)) . " = getAll" . ucfirst(str_replace("tb_", "", strtolower($v_table_name))) . "(\$v_where_clause,\$v_offset ,\$v_num_row);
";

	$v_str .= '$v_dsp_' . str_replace("tb_", "", strtolower($v_table_name)) . '_list = \'<div>
							<div class="element_title">
								<div class="f_left label_60" align="center">\'._LB_ORDER.\'</div>
								<div class="f_left label_240">\'._LB_NAME.\'</div>
								<div class="f_left label_60" align="center">#</div>
							</div>
						<div class="clear height_3"></div>\';
    $v_inc = 1;
while ( $arr_' . str_replace("tb_", "", strtolower($v_table_name)) . ' = mysql_fetch_array($rs_all_' . str_replace("tb_", "", strtolower($v_table_name)) . ',MYSQL_NUM)){
';

	for ($i = 0; $i < sizeof($arr_table_column); $i++) {
		if ($i == 0)
			$v_str.="	\$v_" . strtolower($arr_table_column[$i][0]) . "=\$arr_" . str_replace("tb_", "", strtolower($v_table_name)) . "[\"" . $i . "\"];\r\n";
		else
			$v_str.="	\$v_" . strtolower($arr_table_column[$i][0]) . "=\$arr_" . str_replace("tb_", "", strtolower($v_table_name)) . "[\"" . $i . "\"];\r\n";
	}

	$v_str .= "	
	\$v_dsp_" . str_replace("tb_", "", strtolower($v_table_name)) . "_list .='
	<div class=\"element\">
		<div class=\"contain_" . str_replace("tb_", "", strtolower($v_table_name)) . "\" id=\"contain_" . str_replace("tb_", "", strtolower($v_table_name)) . "_'.\$v_" . str_replace("tb_", "", strtolower($v_table_name)) . "_id.'\">
				<div class=\"f_left label_60\" align=\"center\">'.\$v_inc.'.</div>
			<div class=\"f_left label_240\">
						<a href=\"javascript:void(0)\" onclick=\"load_" . str_replace("tb_", "", strtolower($v_table_name)) . "_detail(\''.\$v_" . str_replace("tb_", "", strtolower($v_table_name)) . "_id.'\')\">'.\$v_" . strtolower($arr_table_column[0][0]) . ".'</a>                 
			</div>
			<div class=\"f_left label_60\" align=\"center\">
					<a onclick=\\'if(!confirm(\"Chac chan chua\")){return false;}\\' href=\"" . $v_url . "&" . strtolower($v_parent_action) . "=" . substr(str_replace("TB_", "", strtoupper($v_table_name)), 0, 4) . "&" . strtolower(substr(str_replace("TB_", "", strtoupper($v_table_name)), 0, 4)) . "=D&hdn_" . strtolower($arr_table_column[0][0]) . "='.\$v_" . strtolower($arr_table_column[0][0]) . ".'\">
						'._IMG_DELETE.'</a>
			</div>
			<div class=\"clear height_3\"></div>
		</div>
    </div>';	
        \$v_inc++;
";

	$v_str.="
}
\$v_dsp_" . str_replace("tb_", "", strtolower($v_table_name)) . "_list .='</div>';";

	$v_str .="		
\$v_number_of_all_result = countAll(\$v_where_clause,'" . $v_table_name . "');
?>
";
	return $v_str;
}

function create_delete_file() {
	global $arr_table_column, $v_table_name, $v_url;
	$arr_url = explode("=", $v_url);
	$v_parent_action = $arr_url[sizeof($arr_url) - 1];
	$v_str = "<?php if (!isset(\$v_sval)) exit; ?>
<?php
	\$v_" . strtolower($arr_table_column[0][0]) . " = (isset(\$_REQUEST[\"hdn_" . strtolower($arr_table_column[0][0]) . "\"])) ? \$_REQUEST[\"hdn_" . strtolower($arr_table_column[0][0]) . "\"] : 0;
	mysql_query(\" DELETE FROM " . strtoupper($v_table_name) . " WHERE " . strtoupper($arr_table_column[0][0]) . " =  '\"." . "\$v_" . strtolower($arr_table_column[0][0]) . ".\"'	 \")or die(mysql_error());
	redir(\$_SERVER[\"HTTP_REFERER\"]);
?>	
";
	return $v_str;
}

function create_update_file() {
	global $arr_table_column, $v_table_name, $v_url;
	$arr_url = explode("=", $v_url);
	$v_parent_action = $arr_url[sizeof($arr_url) - 1];
	$v_str = "<?php if (!isset(\$v_sval)) exit; ?>
<?php
";
	$v_str .= "	\$v_" . strtolower($arr_table_column[0][0]) . " = (isset(\$_REQUEST[\"hdn_" . strtolower($arr_table_column[0][0]) . "\"])) ? \$_REQUEST[\"hdn_" . strtolower($arr_table_column[0][0]) . "\"] : 0;\r\n";
	for ($i = 1; $i < sizeof($arr_table_column); $i++) {
		if ($i == 1)
			$v_str .= "		\$v_" . strtolower($arr_table_column[$i][0]) . " = (isset(\$_REQUEST[\"txt_" . strtolower($arr_table_column[$i][0]) . "\"])) ? \$_REQUEST[\"txt_" . strtolower($arr_table_column[$i][0]) . "\"] : 0;\r\n";
		else
			$v_str .= "		\$v_" . strtolower($arr_table_column[$i][0]) . " = (isset(\$_REQUEST[\"txt_" . strtolower($arr_table_column[$i][0]) . "\"])) ? \$_REQUEST[\"txt_" . strtolower($arr_table_column[$i][0]) . "\"] : 0;\r\n";
	}

	$v_str .= "
if (!" . "\$v_" . strtolower($arr_table_column[0][0]) . "){
	" . "\$v_" . strtolower($arr_table_column[0][0]) . " = insert" . ucfirst(str_replace("tb_", "", strtolower($v_table_name))) . "(
";

	for ($i = 1; $i < sizeof($arr_table_column); $i++) {
		if ($i == 1)
			$v_str.="		\$v_" . strtolower($arr_table_column[$i][0]) . "\r\n";
		else
			$v_str.="			,\$v_" . strtolower($arr_table_column[$i][0]) . "\r\n";
	}

	$v_str .= "		
		 );
}else{
	update" . ucfirst(str_replace("tb_", "", strtolower($v_table_name))) . "(
";
	for ($i = 0; $i < sizeof($arr_table_column); $i++) {
		if ($i == 0)
			$v_str.="		\$v_" . strtolower($arr_table_column[$i][0]) . "\r\n";
		else
			$v_str.="			,\$v_" . strtolower($arr_table_column[$i][0]) . "\r\n";
	}

	$v_str .= "		
	 );	
}
redir(\"" . $v_url . "&" . strtolower($v_parent_action) . "=" . substr(str_replace("TB_", "", strtoupper($v_table_name)), 0, 4) . "&" . strtolower(substr(str_replace("TB_", "", strtoupper($v_table_name)), 0, 4)) . "=A\");
?>	
";
	return $v_str;
}

function create_dsp_singer_file() {
	global $arr_table_column, $v_table_name, $v_url;
	$arr_url = explode("=", $v_url);
	$v_parent_action = $arr_url[sizeof($arr_url) - 1];
	$v_str = "<?php if (!isset(\$v_sval)) exit; ?>
    <form action=\"" . $v_url . "&" . strtolower($v_parent_action) . "=" . substr(str_replace("TB_", "", strtoupper($v_table_name)), 0, 4) . "\" method=\"POST\" >
    <input type=\"hidden\" name=\"" . strtolower(substr(str_replace("TB_", "", strtoupper($v_table_name)), 0, 4)) . "\" value=\"U\">
    <input type=\"hidden\" name=\"hdn_" . strtolower($arr_table_column[0][0]) . "\" value=\"<?php echo " . "\$v_" . strtolower($arr_table_column[0][0]) . "; ?>\">
    <table class=\"list_table\" cellpadding=3 cellspacing=0 border=1 >
    ";

	for ($i = 1; $i < sizeof($arr_table_column); $i++) {
		$v_input = "<input type='text' name=\"txt_" . strtolower($arr_table_column[$i][0]) . "\" value='<?php echo " . "\$v_" . strtolower($arr_table_column[$i][0]) . "; ?>' >";
		if (strpos("text", (string)$arr_table_column[1]) !== false)
			$v_input_type = "<textarea name=\"txt_" . strtolower($arr_table_column[$i][0]) . "\"><?php echo " . "\$v_" . strtolower($arr_table_column[$i][0]) . "; ?></textarea>";
		if ($i == 1)
			$v_str.="	<tr><td>" . strtolower($arr_table_column[$i][0]) . ": </td><td>" . $v_input . "</td></tr>\r\n";
		else
			$v_str.="		<tr><td>" . strtolower($arr_table_column[$i][0]) . ": </td><td>" . $v_input . "</td></tr>\r\n";
	}
	$v_str.="
    </table>
    <input type='submit' value='C&#7853;p nh&#7853;t'>
    </form>
    ";
	return $v_str;
}

function create_ajax_info_file() {
	global $arr_table_column, $v_table_name;
	$v_str = "<?php if (!isset(\$v_sval)) exit; ?>
            <?php
            " . "\$v_" . strtolower($arr_table_column[0][0]) . " = (isset(\$_REQUEST[\"hdn_" . strtolower($arr_table_column[0][0]) . "\"])) ? \$_REQUEST[\"hdn_" . strtolower($arr_table_column[0][0]) . "\"] : 0;
    ";
	$v_str .= "
            \$rs_" . str_replace("tb_", "", strtolower($v_table_name)) . " = getSinger" . ucfirst(str_replace("tb_", "", strtolower($v_table_name))) . "(" . "\$v_" . strtolower($arr_table_column[0][0]) . ");
            if (\$arr_" . str_replace("tb_", "", strtolower($v_table_name)) . " = mysql_fetch_array(\$rs_" . str_replace("tb_", "", strtolower($v_table_name)) . ",MYSQL_NUM)){
    ";

	for ($i = 0; $i < sizeof($arr_table_column); $i++) {
		if ($i == 0)
			$v_str.="		\$v_" . strtolower($arr_table_column[$i][0]) . "=\$arr_" . str_replace("tb_", "", strtolower($v_table_name)) . "[\"" . $i . "\"];\r\n";
		else
			$v_str.="			\$v_" . strtolower($arr_table_column[$i][0]) . "=\$arr_" . str_replace("tb_", "", strtolower($v_table_name)) . "[\"" . $i . "\"];\r\n";
	}
	$v_str .= "
            }else{
    ";
	for ($i = 0; $i < sizeof($arr_table_column); $i++) {
		if ($i == 0)
			$v_str.="		\$v_" . strtolower($arr_table_column[$i][0]) . "=\"\";\r\n";
		else
			$v_str.="			\$v_" . strtolower($arr_table_column[$i][0]) . "=\"\";\r\n";
	}
	$v_str .= "
            }
    ";

	$v_str .= "
    
    ";
	global $arr_table_column, $v_table_name, $v_url;
	$arr_url = explode("=", $v_url);
	$v_parent_action = $arr_url[sizeof($arr_url) - 1];
	$v_str .= " echo '
	<div class=\"panel\">
	<div class=\"current_path\">'._LB_INFO.'</div><br/>
    <form action=\"" . $v_url . "&" . strtolower($v_parent_action) . "=" . substr(str_replace("TB_", "", strtoupper($v_table_name)), 0, 4) . "\" method=\"POST\" >
    <input type=\"hidden\" name=\"" . strtolower(substr(str_replace("TB_", "", strtoupper($v_table_name)), 0, 4)) . "\" value=\"U\">
    <input type=\"hidden\" name=\"hdn_" . strtolower($arr_table_column[0][0]) . "\" value=\"'. " . "\$v_" . strtolower($arr_table_column[0][0]) . ".'\">\n";

	for ($i = 1; $i < sizeof($arr_table_column); $i++) {
		$v_input = "<input type=\"text\" name=\"txt_" . strtolower($arr_table_column[$i][0]) . "\" value=\"'." . "\$v_" . strtolower($arr_table_column[$i][0]) . ".'\" >";
		if (strpos("text", (string)$arr_table_column[1]) !== false)
			$v_input_type = "<textarea name=\"txt_" . strtolower($arr_table_column[$i][0]) . "\">'. " . "\$v_" . strtolower($arr_table_column[$i][0]) . ".'</textarea>";
		
		$v_str.="<div class=\"f_left label_100\">'. _LB_" . strtoupper($arr_table_column[$i][0]) . ".' : </div>
				 <div class=\"f_left\">" . $v_input . "</div>
				 <div class=\"clear\"></div>\n";
	}
	$v_str.="
	<div align=\"center\"><input type=\"submit\" class=\"button\" value=\"'._LB_UPDATE.'\"></div>
    </form> ' ?> ";
	return $v_str;
}

function create_dsp_all_file() {
	global $arr_table_column, $v_table_name, $v_url;
	$arr_url = explode("=", $v_url);
	$v_parent_action = $arr_url[sizeof($arr_url) - 1];
	$v_str = "<?php if (!isset(\$v_sval)) exit; ?>
	<div class=\"path\">
		<a href=\"?a=ACC\"><?php echo _LB_ACCOUNT_PATH; ?></a>
		<?php echo _IMG_ARROR_PATH; ?>
		<span class=\"current_path\"><?php echo _LB_". str_replace("TB_", "", strtoupper($v_table_name)) ."_PATH ?></span>
	</div>
	<div class=\"f_left width_30 panel\" id=\"" . str_replace("tb_", "", strtolower($v_table_name)) . "_contain\">
		<div class=\"f_right\">
			 <a href=\"javascript:void(0)\" onclick=\"load_" . str_replace("tb_", "", strtolower($v_table_name)) . "_detail('0')\"><?php echo _IMG_ADD . ' ' . _LB_ADD; ?> </a>
		</div>
		<br/>
		<?php echo \$v_dsp_" . str_replace("tb_", "", strtolower($v_table_name)) . "_list; ?>
        <?php include \"lib/paging.php\" ?> 
	</div>
	<div class=\"f_left width_65\" id=\"" . str_replace("tb_", "", strtolower($v_table_name)) . "_detail_contain\" style=\"padding-top:0px;height: 400px\">
	</div>
	<div class=\"clear\"></div>
	
<script type=\"text/javascript\">
    function load_" . str_replace("tb_", "", strtolower($v_table_name)) . "_detail(p_" . str_replace("tb_", "", strtolower($v_table_name)) . "_id){
         $.ajax({
           url:'<?php echo URL;?>?a=ACC&acc=" . substr(str_replace("TB_", "", strtoupper($v_table_name)), 0, 4) . "&" . substr(str_replace("tb_", "", strtolower($v_table_name)), 0, 4) . "=" . substr(str_replace("TB_", "", strtoupper($v_table_name)), 0, 2) . "IF',
           data: 'hdn_" . str_replace("tb_", "", strtolower($v_table_name)) . "_id='+p_" . str_replace("tb_", "", strtolower($v_table_name)) . "_id,
           beforeSend: function() {
			     $('#" . str_replace("tb_", "", strtolower($v_table_name)) . "_detail_contain').html('<?php echo _IMG_LOADING; ?>');
			},
           success: function(data) {
                $('#" . str_replace("tb_", "", strtolower($v_table_name)) . "_detail_contain').html(data);
                $('.contain_" . str_replace("tb_", "", strtolower($v_table_name)) . "').css({background :'none'});
                $('#contain_" . str_replace("tb_", "", strtolower($v_table_name)) . "_'+p_" . str_replace("tb_", "", strtolower($v_table_name)) . "_id).css({'background': '#d3eead'})
           }
        });
    }
</script>

";
	return $v_str;
}

?>